<?php /* Template_ 2.2.4 2011/07/08 14:52:54 E:\PHP\www\sagapo\_DATA\template_\skin\default\add.html 000005042 */ 
$TPL_category_1=empty($TPL_VAR["category"])||!is_array($TPL_VAR["category"])?0:count($TPL_VAR["category"]);?>
<div class="default">
	
	
	<form name="<?php echo $TPL_VAR["module"]?>_add" id="<?php echo $TPL_VAR["module"]?>_add" method="post" action="<?php echo $TPL_VAR["action"]?>/doAdd" enctype="multipart/form-data">
		<table class="table">
			<caption>
				게시판 추가
			</caption>
			<colgroup>
				<col class="t_add" />
				<col />
			</colgroup>
			<tbody>
<?php if($TPL_VAR["binfo"]->ba_category){?>
				<tr>
					<th scope="row" class="txt_right br"><label for="<?php echo $TPL_VAR["module"]?>_category">카테고리</label></th>
					<td>
						<select name="<?php echo $TPL_VAR["module"]?>_category" id="<?php echo $TPL_VAR["module"]?>_category">
<?php if($TPL_category_1){foreach($TPL_VAR["category"] as $TPL_V1){?>
							<option value="<?php echo $TPL_V1->bc_seq?>"><?php echo $TPL_V1->bc_name?></option>
<?php }}?>
						</select>
					</td>
				</tr>
<?php }?>
				<tr>
					<th scope="row" class="txt_right br"><label for="<?php echo $TPL_VAR["module"]?>_subject">제목</label></th>
					<td>
						<input type="text" name="<?php echo $TPL_VAR["module"]?>_subject" id="<?php echo $TPL_VAR["module"]?>_subject" class="subject required" placeholder="제목" />
						<input type="hidden" name="<?php echo $TPL_VAR["module"]?>_bid" value="<?php echo $TPL_VAR["binfo"]->ba_id?>" />
					</td>
				</tr>
				<tr>
					<th scope="row" class="txt_right br"><label for="<?php echo $TPL_VAR["module"]?>_content">내용</label></th>
					<td>
						<textarea id="<?php echo $TPL_VAR["module"]?>_content" name="<?php echo $TPL_VAR["module"]?>_content" class="required" placeholder="내용"></textarea>
					</td>
				</tr>
<?php if($TPL_VAR["binfo"]->ba_attach){?>
				<tr>
					<th scope="row" class="txt_right br">첨부파일</th>
					<td>
						<script>
							$(function() {
								
								
								
							});
						</script>
						<div id="<?php echo $TPL_VAR["module"]?>_fileupload" class="fileupload">
							You browser doesn't support native upload. Try Firefox 3 or Safari 4.
						</div>
						
						<input type='text' name="<?php echo $TPL_VAR["module"]?>_files" id="<?php echo $TPL_VAR["module"]?>_files" />
					</td>
				</tr>
<?php }?>
			</tbody>
		</table>
		<div class="button_area">
			<button type="submit">전송</button>
			<button type="button" class="cancel" onclick="history.back(-1)">뒤로</button>
		</div>
		<div id="log">
		
		</div>
	</form>
	<script>
		$(function() {
			$('#<?php echo $TPL_VAR["module"]?>_add :radio').checkbox({empty:'<?php echo $TPL_VAR["CFG"]->PATH->CSS?>/images/empty.png'});
			
			
			$("#<?php echo $TPL_VAR["module"]?>_content").cleditor()[0].focus();
			
			
<?php if($TPL_VAR["binfo"]->ba_attach){?>
				$("#<?php echo $TPL_VAR["module"]?>_fileupload").pluploadQueue({
					// General settings
					 runtimes : 'html5'
					,url : '/default/doFileUpload'
					,max_file_size : '10mb'
					,chunk_size : '10mb'
					,filters : [
						{title : "Image files", extensions : "jpg,gif,png"},
						{title : "Zip files", extensions : "zip"},
						{title : "PDF files", extensions : "pdf"}
					]
	
					// Resize images on clientside if we can
					//,resize : {width : 320, height : 240, quality : 90}
				
					,init : {
						FileUploaded: function(up, file, info) {
							 // seq값 받아와서 hidden column에 때려 넣어야함.
							 info = $.parseJSON(info.response);
							 
							 
							 if($("#<?php echo $TPL_VAR["module"]?>_files").val() != "") {
								 files = $("#<?php echo $TPL_VAR["module"]?>_files").val(); 
								 $("#<?php echo $TPL_VAR["module"]?>_files").val(files+","+info.result.seq);
							 } else {
								 $("#<?php echo $TPL_VAR["module"]?>_files").val(info.result.seq)
							 }
						}
					}
				});
				
				// 서브밋시 파일업로드가 안된거 있으면 추가 시키기
				$("#<?php echo $TPL_VAR["module"]?>_add").validate({
					submitHandler : function(form) {
						var uploader = $('#<?php echo $TPL_VAR["module"]?>_fileupload').pluploadQueue();
						alert("aa");
						// Validate number of uploaded files
				        if (uploader.total.uploaded == 0) {
				        	// Files in queue upload them first
				            if (uploader.files.length > 0) {
				            	// When all files are uploaded submit form
				                uploader.bind('UploadProgress', function() {
				                	if (uploader.total.uploaded == uploader.files.length) {
				                    	form.submit();
				                	}
				                });
				                
				            	uploader.start();
				            }
				        }	
					}
				});
<?php }else{?>
				$("#<?php echo $TPL_VAR["module"]?>_add").validate();
<?php }?>
		});
	</script>
</div>